type DownloadFileParams = {
	data: BlobPart;
	fileName: string;
};
// #----------- 上: ts类型定义 ----------- 分割线 ----------- 下: JS代码 -----------

const downloadFile = ({ data, fileName }: DownloadFileParams) => {
	try {
		const blob = new Blob([data], { type: 'text/plain' });
		const link = document.createElement('a');
		link.href = URL.createObjectURL(blob);

		link.download = fileName; // 设置下载文件名
		document.body.appendChild(link);
		link.click();
		link.remove();
	} catch (error) {
		console.log(error);
	}
};

export { downloadFile };
